package com.beyond.trace.domain.vo.Knowledge;

import com.beyond.trace.domain.knowledgebase.DiseasePestKnowledge;
import com.beyond.trace.domain.knowledgebase.KnowledgeBase;
import com.ruoyi.common.annotation.Excel;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.common.utils.StringUtils;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import javax.validation.constraints.NotBlank;
import java.util.Date;

/**
 * @ClassName: PestKnowledgeBaseExcel
 * @author: z越
 * @date: 2024/2/18  16:01
 * @description
 */
@Data
@ApiModel("虫害知识库")
public class PestKnowledgeBase {
    @ApiModelProperty("主键id(新增时不填，修改时必填)")
    private Long id;
    @Excel(name = "虫害名称",prompt = "必填")
    @ApiModelProperty("虫害名称")
    @NotBlank(message = "虫害名称不能为null")
    private String pestName;
    @Excel(name = "病虫害简介")
    @ApiModelProperty("病虫害简介")
    private String blurb;
    @Excel(name = "形态特征")
    @ApiModelProperty("形态特征")
    private String formFeature;
    @Excel(name = "发生规律")
    @ApiModelProperty("发生规律")
    private String law;
    @Excel(name = "危害特征")
    @ApiModelProperty("危害特征")
    private String hazardFeature;
    @Excel(name = "防治办法")
    @ApiModelProperty("防治办法")
    private String cure;
    @Excel(name = "图片1")
    @ApiModelProperty("图片1")
    private String picture1;
    @Excel(name = "图片2")
    @ApiModelProperty("图片2")
    private String picture2;
    @Excel(name = "图片3")
    @ApiModelProperty("图片3")
    private String picture3;

    @ApiModelProperty("图片地址（界面新增时或修改时使用，多个用‘，’隔开）")
    private String pictures;

    public KnowledgeBase toPo(){
        KnowledgeBase po = new KnowledgeBase();
        po.setCreateTime(new Date());
        po.setName(this.pestName);
        po.setProfile(this.blurb);
        po.setFormFeature(this.formFeature);
        po.setPictures(this.pictures);

        if (StringUtils.isNotEmpty(this.picture1) || StringUtils.isNotEmpty(this.picture2) || StringUtils.isNotEmpty(this.picture3)){
            po.setPictures(this.picture1 + "," + this.picture2 + "," + this.picture3);
        }
        po.setType("pest");
        po.setCreateBy(SecurityUtils.getUsername());
        DiseasePestKnowledge extend = new DiseasePestKnowledge();
        if (StringUtils.isNotEmpty(this.law)){
            extend.setLaw(this.law);
        }
        if (StringUtils.isNotEmpty(this.hazardFeature)){
            extend.setHazardFeature(this.hazardFeature);
        }
        if (StringUtils.isNotEmpty(this.cure)){
            extend.setCure(this.cure);
        }
        po.setExtend(extend);
        return po;
    }
}
